/*
 * Copyright (c) zero. 2022-2023. All rights reserved.
 *
 */

package json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName CustomDateSerializer
 * @Description TODO
 * @Author lin
 * @DATE 2023/4/11 12:03 AM
 * @Version 1.0
 */
public class CustomDateSerializer extends StdSerializer<Date> {
    private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    public CustomDateSerializer() { this(null); }
    public CustomDateSerializer(Class<Date> t) { super(t); }
    @Override
    public void serialize(Date value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
        gen.writeString(formatter.format(value));
    }
}
